package com.jianhua.backend.controller;

import com.jianhua.backend.domain.entity.PackageDishes;
import com.jianhua.backend.service.PackageDishesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 记录套餐中包含的具体菜品及类型 前端控制器
 * </p>
 *
 * @author mahang
 * @since 2025-07-02
 */
@RestController
@RequestMapping("/package-dishes")
public class PackageDishesController {

    @Autowired
    private PackageDishesService packageDishesService;

    /**
     * 查询所有套餐关联的菜品信息
     */
    @GetMapping
    public List<PackageDishes> getAllPackageDishes() {
        return packageDishesService.list();
    }

    /**
     * 根据ID查询套餐关联的菜品信息
     */
    @GetMapping("/{id}")
    public PackageDishes getPackageDishesById(@PathVariable Integer id) {
        return packageDishesService.getById(id);
    }

    /**
     * 创建新的套餐关联菜品记录
     */
    @PostMapping
    public boolean createPackageDishes(@RequestBody PackageDishes packageDishes) {
        return packageDishesService.save(packageDishes);
    }

    /**
     * 更新指定ID的套餐关联菜品记录
     */
    @PutMapping("/{id}")
    public boolean updatePackageDishes(
            @PathVariable Integer id,
            @RequestBody PackageDishes packageDishes) {
        packageDishes.setId(id);
        return packageDishesService.updateById(packageDishes);
    }

    /**
     * 删除指定ID的套餐关联菜品记录
     */
    @DeleteMapping("/{id}")
    public boolean deletePackageDishes(@PathVariable Integer id) {
        return packageDishesService.removeById(id);
    }
}
